const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    latitude: Number,
    longitude: Number,
    title: "",
    contact_p: "",
    id_card: "",
    phone: "",
    content: "",
    address: "",
    type: "",
    imgList: [],
    imgList_2: []
  },


  onChange_pick(e) {
    this.setData({
      type: e.detail
    })
  },

  get_location() {
    let that = this
    wx.getLocation({
      type: 'gcj02', //返回可以用于wx.openLocation的经纬度
      success(res) {
        const latitude = res.latitude
        const longitude = res.longitude
        console.log(res);
        that.setData({
          latitude,
          longitude
        })
      }
    })
  },

  delete_img(e) {
    let index = e.detail.index
    let imgList = this.data.imgList
    imgList.splice(index, 1)
    this.setData({
      imgList
    })
    console.log(index)
    console.log(imgList);
  },

  delete_img2(e) {
    let index = e.detail.index
    let imgList_2 = this.data.imgList_2
    imgList_2.splice(index, 1)
    this.setData({
      imgList_2
    })
    console.log(index)
  },

  afterRead(event) {
    let that = this
    console.log(event);
    const {
      file
    } = event.detail;
    wx.uploadFile({
      url: 'https://vip.join.ink/api/upload/img',
      filePath: file.url,
      name: 'file',
      formData: {
        user: 'upload'
      },
      success(res) {
        let url = JSON.parse(res.data)
        url = "https://vip.join.ink/" + url.path
        console.log(url, "url");
        let {
          imgList
        } = that.data;
        imgList = [{
          url: url
        }]
        that.setData({
          imgList
        });
      },
    });


  },

  afterRead2(event) {
    let that = this
    console.log(event);
    const {
      file
    } = event.detail;
    wx.uploadFile({
      url: 'https://vip.join.ink/api/upload/img',
      filePath: file.url,
      name: 'file',
      formData: {
        user: 'upload'
      },
      success(res) {
        let url = JSON.parse(res.data)
        url = "https://vip.join.ink/" + url.path
        console.log(url, "url");
        let {
          imgList_2
        } = that.data;
        imgList_2 = [{
          url: url
        }]
        that.setData({
          imgList_2
        });
      },
    });
  },

  submit_info() {
    let options = JSON.parse(JSON.stringify(this.data))
    options.lat = this.data.latitude
    options.lng = this.data.longitude
    options.id_card_z = this.data.imgList[0].url
    options.id_card_f = this.data.imgList_2[0].url
    delete options.latitude
    delete options.longitude
    delete options.imgList
    delete options.imgList_2
    delete options.__webviewId__
  

    console.log(options);
    app.request("/user/settled", {
      method: "POST",
      data: options
    }).then(res => {
      console.log(res, "注册");
      if(res.data.code==200){
        wx.setStorageSync('is_audit', )
      }
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.get_location()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
  
})